<template>
  <div
    class="long-pass"
    v-loading="loading"
    element-loading-text="正在加载数据..."
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <div class="left-box" v-if="!loading">
      <div class="playground-container">
        <div class="playground-top">
          <div class="success-detail">
            <img src="../../assets/image/pass/solid.png" alt="" />
            <span>成功长传</span>
          </div>
          <div class="fail-detail">
            <img src="../../assets/image/pass/dash.png" alt="" />
            <span>失败长传</span>
          </div>
        </div>
        <PlayGround
          :my_accurate_long_ball="my_accurate_long_ball"
          :my_inaccurate_long_ball="my_inaccurate_long_ball"
        />
        <div class="legend">
          <img
            class="attack-arrow"
            src="../../assets/image/playerGround/rightArrow.png"
            alt=""
          />
        </div>
      </div>
    </div>
    <div class="right-box" v-if="!loading">
      <div class="ant-v">
        <div class="two-graph">
          <div class="one-graph">
            <div class="one-graph-title">长传总数/成功率</div>
            <LongScatter
              :long-pass="longPass.longPass"
              :player-name="longPass.playerName"
            />
          </div>
          <div class="one-graph">
            <div class="one-graph-title">长传成功率/90</div>
            <LongPassSuccessful
              :long-success="longPass['longPassAccuracy/90']"
            />
          </div>
        </div>
        <div class="graph-legend">
          {{ longPass.playerName }}在中超的传球数据与其他球员的对比
        </div>
      </div>
      <LongPassTableData :table="longPass.Table"></LongPassTableData>
    </div>
  </div>
</template>

<script>
import LongPassTotal from "../ant_v/longPass/LongPassTotal";
import LongScatter from "../ant_v/longPass/LongScatter";
import LongPassSuccessful from "../ant_v/longPass/LongPassSuccessful";
import LongPassTableData from "../tableData/LongPassTableData";
import PlayGround from "../playground/PlayGround";
import axios from "axios";
export default {
  name: "LongPass",
  data() {
    return {
      loading: true,
      longPass: "",
    };
  },
  components: {
    LongPassTotal,
    LongPassSuccessful,
    LongPassTableData,
    PlayGround,
    LongScatter,
  },
  watch: {
    $route: {
      handler(to, from) {
        console.log("from:", from);
        console.log("to:", to);
        const { playerId } = to.params;
        // console.log("toId:", playerId);
        if (playerId) {
          this.getLongPass(playerId);
        }
      },
      immediate: true,
    },
  },
  computed: {
    my_accurate_long_ball() {
      return this.longPass.accurate_long_ball.map((item) => {
        return {
          x1: item.x1 + "%",
          y1: item.y1 + "%",
          x2: item.x2 + "%",
          y2: item.y2 + "%",
        };
      });
    },
    my_inaccurate_long_ball() {
      return this.longPass.inaccurate_long_ball.map((item) => {
        return {
          x1: item.x1 + "%",
          y1: item.y1 + "%",
          x2: item.x2 + "%",
          y2: item.y2 + "%",
        };
      });
    },
  },
  async mounted() {
    // const playerId = this.$store.state.currPlayerId;
    // this.getLongPass(playerId);
  },
  methods: {
    async getLongPass(playerId) {
      const { data } = await axios.get(
        `http://8.141.159.127:3000/api/v1/players/actions/longpass/${playerId}`
      );
      this.longPass = data;
      this.loading = false;
    },
  },
};
</script>

<style scoped lang="scss">
.long-pass {
  display: flex;
  width: 100%;
  height: 100%;
  justify-content: space-between;
}
.left-box {
  height: 456px;
  margin-left: 90px;
}
.right-box {
  width: 560px;
  height: 413px;
  margin-top: 18px;
  margin-right: 70px;
  /*background-color: yellow;*/
}
.playground-container {
  position: relative;
  width: 620px;
  height: 456px;
  /*background-color: red;*/
  margin-top: 18px;
  .playground-top {
    display: flex;
    justify-content: flex-start;
    width: 591px;
    color: #656f73;
    line-height: 25px;
    font-size: 16px;
    height: 25px;
    text-align: left;
    /*background-color: #656F73;*/
    div {
      width: 100px;
      height: 25px;
      /*background-color: yellow;*/
      display: flex;
      justify-content: space-between;
      align-items: center;
      img {
        /*background-color: orange;*/
        width: 35px;
        height: 25px;
      }
    }
    .fail-detail {
      margin-left: 20px;
    }
  }
  .playground-right {
    /*display: inline-block;*/
    position: absolute;
    top: 30px;
    left: 603px;
    color: #bd1e1e;
    display: flex;
    /*flex-direction: column;*/
    justify-content: space-between;
    /*align-items: center;*/
    /*<!--margin-left: 9px;-->*/
    /*<!--margin-right: -28px;-->*/
    /*<!--margin-bottom: 17px;-->*/
    width: 17px;
    height: 383px;
    writing-mode: vertical-lr;
    font-size: 18px;
    /*background-color: red;*/
    .little-block {
      height: 3px;
      background-color: #bbbbbb;
      font-size: 25px;
    }
    .rate {
      /*background-color: red;*/
      line-height: 16px;
    }
  }
  .legend {
    display: flex;
    justify-content: space-between;
    /*background-color: yellow;*/
    font-size: 14px;
    width: 591px;
    height: 40px;
    /*margin-top: 22px;*/
    .attack-arrow {
      width: 150px;
      /*height: 20px;*/
    }
  }
}
.ant-v {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  /*background-color: red;*/
  line-height: 10px;
  width: 100%;
  height: 223px;
  .two-graph {
    display: flex;
    justify-content: space-between;
    .one-graph {
      width: 230px;
      height: 200px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      .one-graph-title {
        height: 20px;
        line-height: 20px;
      }
    }
  }
  .graph-legend {
    height: 25px;
    color: #656f73;
    font-size: 14px;
    line-height: 25px;
  }
}
</style>
